package com.marketing.tenant.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.marketing.tenant.entity.SubscriptionPlan;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 订阅计划Mapper接口
 * 
 * @author Marketing System
 * @since 2024-09-25
 */
@Mapper
public interface SubscriptionPlanMapper extends BaseMapper<SubscriptionPlan> {
    
    /**
     * 分页查询可用的订阅计划
     * 
     * @param page 分页参数
     * @return 分页结果
     */
    @Select("SELECT * FROM saas_subscription_plan WHERE status = 1 AND deleted = 0 ORDER BY plan_name ASC")
    IPage<SubscriptionPlan> selectActivePlans(Page<SubscriptionPlan> page);
    
    /**
     * 根据名称查询订阅计划
     * 
     * @param planName 计划名称
     * @return 订阅计划
     */
    @Select("SELECT * FROM saas_subscription_plan WHERE plan_name = #{planName} AND status = 1 AND deleted = 0")
    SubscriptionPlan selectByPlanName(@Param("planName") String planName);
    
    /**
     * 根据价格范围查询订阅计划
     * 
     * @param minPrice 最低价格
     * @param maxPrice 最高价格
     * @return 订阅计划列表
     */
    @Select("SELECT * FROM saas_subscription_plan WHERE price >= #{minPrice} AND price <= #{maxPrice} AND status = 1 AND deleted = 0 ORDER BY price ASC")
    List<SubscriptionPlan> selectByPriceRange(@Param("minPrice") Double minPrice, @Param("maxPrice") Double maxPrice);
    
    /**
     * 根据功能模块查询订阅计划
     * 
     * @param feature 功能模块
     * @return 订阅计划列表
     */
    @Select("SELECT * FROM saas_subscription_plan WHERE JSON_CONTAINS(features, JSON_QUOTE(#{feature})) AND status = 1 AND deleted = 0")
    List<SubscriptionPlan> selectByFeature(@Param("feature") String feature);
    
    /**
     * 获取推荐的订阅计划
     * 
     * @return 推荐计划列表
     */
    @Select("SELECT * FROM saas_subscription_plan WHERE status = 1 AND deleted = 0 ORDER BY plan_name ASC")
    List<SubscriptionPlan> selectRecommendedPlans();
}